﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using StoragePeriod.Data;
using StoragePeriod.Common;
using StoragePeriod.Web.Common;

namespace StoragePeriod.Web.SysManage
{
    public partial class RawTypeManage : SecurityPage
    {
        #region 属性

        #endregion

        #region 继承
        public override string PrivCode()
        {
            return "a531bc536c76a206";
        }
        #endregion

        #region 函数

        private void DataBing()
        {
            int typeid = Convert.ToInt32(Request.QueryString["TypeId"].ToString());
            IQueryable<RawMaterialType> RawType = RawMaterialType.Where("ParentId=@0 and Typeinfoid=@1", 0,typeid);
            this.RepDataList.DataSource = RawType;
            this.RepDataList.DataBind();
        }

        int i = 0;
        public string GetXH()
        {
            i +=1;
            return i.ToString();
        }

        #endregion

        #region 事件

        protected void Page_Load(object sender, EventArgs e)
        {
            if (IsPostBack) return;
            DataBing();
        }

        protected void RepDataList_ItemCommand(object source, RepeaterCommandEventArgs e)
        {
            if (e.CommandName == "Edit")
            {
                int RawTypeId = Convert.ToInt32(e.CommandArgument);
                string strTypeName = RawMaterialType.Where("id=@0", RawTypeId).First().TypeName;
                this.HidTypeID.Value = RawTypeId.ToString();
                UtilityUI.Load(this.upPanelMain, "LoadData('" + strTypeName + "');ShowDlg(1)");
            }
            else
            {
                int RawTypeId = Convert.ToInt32(e.CommandArgument);
                RawMaterialType.Delete("id=@0", RawTypeId);
                DataBing();
                UtilityUI.Load(this.upPanelMain, "alertstr('删除成功！')");
            }
        }

        protected void btPost_Click(object sender, EventArgs e)
        {
            if (this.HidIsEdit.Value == "0")
            {
                int typeid = Convert.ToInt32(Request.QueryString["TypeId"].ToString());
                RawMaterialType md = new RawMaterialType();
                md.ParentId = 0;
                md.TypeName = this.txt_RawTypeName.Text.Trim();
                md.TypeInfoid = typeid;
                RawMaterialType.Insert(md);
                DataBing();
            }
            else
            { 
                int RawTypeId = Convert.ToInt32(this.HidTypeID.Value);
                RawMaterialType md = RawMaterialType.Where("id=@0", RawTypeId).First();
                md.TypeName = this.txt_RawTypeName.Text.Trim();
                RawMaterialType.Update(md, "id=@0", RawTypeId);
                DataBing();
            }
        }
        #endregion
    }
}